package com.yueyin.ui.main;

import android.app.Activity;
import android.database.Cursor;

import java.util.ArrayList;
import java.util.List;

public class MusicList {
    Activity activity;
    public List<Data> dataList = new ArrayList<>();

    public MusicList(Activity activity) {
        this.activity = activity;
    }

    public List<Data> showMusicList() {
        Cursor cursor = new SQLiteHelper(activity.getApplicationContext()).selectAll();
        dataList.clear();

        String musicName;

        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            int index = cursor.getColumnIndex("name");
            musicName = cursor.getString(index > -1 ? index : 0);
            Data data = new Data();
            data.setName(musicName);

            dataList.add(data);
        }

        cursor.close();

        return dataList;
    }
}
